//1.输出五名同学的学号、姓名、出生日期并统计2000年出生的学生人数
#include <stdio.h>





typedef struct stu{
	char sno[100];
	char name[200];
    
	struct birth{
		int year;
		int month;
		int day;
	}birthday;
}STU;


void swap(STU *stuA,STU  *stuB)
{
    STU temp;
    temp= *stuA;
    *stuA = *stuB;
    *stuB=temp;
}



int main(){
	STU s[5]={{"720191","liu",{2004,3,22}}
	,{"720192","zhu",{1998,1,23}}
	,{"720193","ma",{2013,8,16}}
	,{"720194","wang",{2004,9,2}}
	,{"720195","fan",{2004,9,25}}};

	// int i;
	// int nums=0;
	// for(i=0;i<5;i++){
	// printf("sno:%s\tname:%s\tbirth:%d-%d-%d\n",s[i].sno,s[i].name,s[i].birthday.year ,s[i].birthday.month ,s[i].birthday.day );
	// }

	// for(i=0;i<5;i++){
	// 	if(s[i].birthday.year==2000){
	// 	nums++;
	// 	}
	// }
	// printf("2000年出生的学生人数:%d",nums);


    // 从年份大 到 年份小。 年一样就看月，月份小的排前面。
    // 选择排序法

    /**
    STU s[5]={{"720190001","liuxueqin",{2004,3,22}}
	,{"720190002","zhuqinqin",{1998,1,23}}
	,{"720190003","maxuerong",{2013,8,16}}
	,{"720190004","wangyue",{2000,1,2}}
	,{"720190005","fanyatin",{2004,6,25}}};
    */

    // int  s[5] : [2004, 1998, 2013, 2000, 2004]
    //    i=0      [2013, 1998, 2004, 2000, 2004]
    //    i=1      [2013, 2014, 1998, 2000, 2004]  
    //    i=2      [2013, 2014, 2004, 2000, 1998]   max = 4
    //    i=3      [2013, 2014, 2004, 2000, 1998]  
    //    i=4      [2013, 2014, 2004, 2000, 1998]  
         
    for (int i=0;i<5;i++){
        int max_index = i;
        for (int j=i;j<5;j++){
            if (s[j].birthday.year > s[max_index].birthday.year){
                max_index = j;
            }
            // 如果年份一样:
            else if(s[j].birthday.year == s[max_index].birthday.year ){
                if (s[j].birthday.month > s[max_index].birthday.month){
                    max_index = j;
                }
                // 如果月份一样：
                else if (s[j].birthday.month == s[max_index].birthday.month){
                    if(s[j].birthday.day > s[max_index].birthday.day){
                        max_index =j;
                    }
                }
            }
        }
        swap(&s[i], &s[max_index]);
    }


    for(int i=0;i<5;i++){
	printf("sno:%s\tname:%s\tbirth:%d-%d-%d\n",s[i].sno,s[i].name,s[i].birthday.year ,s[i].birthday.month ,s[i].birthday.day );
	}


	return 0;
	
}

